package com.chinasofti.shoot;

import java.awt.image.BufferedImage;

//英雄小飞机 飞行物
public class Hero extends FlyingObject {
    private int life;
    private int doubleFire;//火力值
    private BufferedImage[] images = {};
    private int index;//辅助图片的切换

    //构造方法

    public Hero() {
        imge = ShootGame.hero0;
        width = imge.getWidth();
        height = imge.getHeight();
        x=150;//固定的x坐标
        y=400;//固定的y坐标
        life = 3;
        doubleFire = 0;
        images = new BufferedImage[]{ShootGame.hero0,ShootGame.hero1};//两张图片
        index=0;
    }

    @Override
    public void step() {//100毫秒切换
        imge = images[index++/10%images.length];
    }
    public  boolean outOfBounds(){
        return false;
    }

    //英雄机发射子弹
    public Bullet[]  shoot(){
        int xStep=this.width/4;
        //单倍火力
        if (doubleFire>0){//双倍火力
            Bullet[] bullets = new  Bullet[2];
            bullets[0]=new Bullet(this.x+1*xStep, this.y-20);
            bullets[1]=new Bullet(this.x+3*xStep, this.y-20);
            doubleFire -=2;
            return bullets;
        }else {
            Bullet[] bullets = new  Bullet[1];
            bullets[0]=new Bullet(this.x+2*xStep, this.y-20);
            return  bullets;
        }
    }
    //让英雄机跟着鼠标激动
    public  void  meoveTo(int x ,int y){
        this.x=x-this.width/2;
        this.y=y-this.height/2;
    }
    //加火力值
    public  void addDoubleFire(){
        doubleFire+=40;
    }
    //增加生命
    public void addLife() {
        life++;
    }
    //获取生命
    public int getLife(){
        return  life;
    }
    //判断英雄机与敌人的碰撞
    public  boolean hit(FlyingObject obj){
        int x1 =obj.x-this.width/2;
        int x2 =obj.x+this.width+this.width/2;
        int y1 = obj.y-this.height/2;
        int y2 = obj.y+this.height+this.height/2;
        int x = this.x +this.width/2;
        int y = this.y+this.height/2;
        return x>x1&&x<x2 && y>y1&&y<y2;
    }
    //减少生命
    public  void  subtractLife(){
        life--;
    }
    //火力清零
    public  void setDoubleFire(int DoubleFire){
        this.doubleFire=DoubleFire;
    }
}
